<?php
/**
 * Account_Controller_Admin
 *  
 * Controller for actions (in admin area) of admin module
 *
 * @version 2012-10-10
 * @package account
 * @subpackage controller
 * @category Account_Controller_Admin
 */
 
 class Home_Controller_Visitor extends Controller
{

	/** 
	* Index
	* Default function that will be used upon module start-up.
    *
    * @version 2012-10-10
    * @param Request $req
    * @return view
    * @access public
    */
    public function processIndex($req)
    {
		return $this->processHome($req);
    }
	
	
   /**
    * Login
    * This function shows admin login form.
	* This function checks whether the "Remember Login" checkbox is checked. If true, login email will be inserted from cookies.
	* 
    * @param Request $req
    * @return View (login page)
    * @access public
    */
    public function processHome($req)
    {
		$view = $this->getView("home");
		return $view;
    }   
    public function processGenres($req)
    {
        $view = $this->getView("genres");
		$view->setVar('genres',Server::getGenres());
        return $view;
    }
    public function processAuthors($req)
    {
        $view = $this->getView("authors");
        return $view;
    }
    public function processPopular($req)
    {
        $view = $this->getView("popular");
        return $view;
    }
	
	public function processBooks($req){
		$url = new Url();
		$url->setParam('page',null);
		$view = $this->getView("books");
		$page = $req->getInt('page',1);
		$genre = $req->getInt('genre',0);
		$data = Server::getBookList(5,$page,$genre);
		
		$view->setVar('rows',$data['books']);
		$pager = _pager($data['pager']);
		
		$view->setVar('pagerInfo',$pager);
		$view->setVar('page_url',$url->getUrl()."&page=");
        return $view;
	}
	
	public function processView($req){
		$url = new Url();
		$url->setParam('page',null);
		$view = $this->getView("page");
		$page = $req->get('page',1);
		$book = $req->get('book',1);
		$result = Server::getPage($book,$page);
		$pager = _pager($result['pager']);
	
		$view->setVar('text',$result['page'],0);
		$view->setVar('pagerInfo',$pager);
		$view->setVar('page_url',$url->getUrl()."&page=");
		return $view;
	}
}